import storejs from 'storejs';
import theme from '@/utils/themeUtil';

let initState = () => ({
  
  // 当前主题名称
  theme: theme.themeName,

  // 当前语言
  locale: storejs('locale') || 'zh-CN',

  //国际化语言类型
  locales: [
    { title: "中文", value: 'zh-CN' },
    { title: "English", value: 'en-US' }
  ],

});

export default {
  namespace: 'masterGlobal',
  state: { ...initState() },
  effects: {
    // 设置主题
    *setTheme({ payload }, { call, put }) {
      theme.setTheme(payload.themeName)
      yield put({
        type: 'setState',
        payload: {theme:payload.themeName},
      });
    },

  },
  reducers: {
    setState(state, action) {
      return { ...state, ...action.payload };
    },
    init(state, action) {
      return { ...initState(), ...action.payload };
    },
  },
};
